﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace CompilerForC.LexerTest
{
    using LexicalAnalysis;

    static class Program
    {
        static void Main()
        {
            // Get source code...
            string source = Properties.Resources.TestProgram;

            // Create lexer and tokenize source code...
            Lexer lexer = new Lexer();
            lexer.Tokenize(source);

            // Print preprocessed source code...
            Console.Write(lexer.PreprocessedSource);
            Console.WriteLine();
            Console.WriteLine();

            // Print lexer table contents...
            PrintReport(lexer.Tables);
        }

        static void PrintReport(LexerTables tables)
        {
            // Print tokens...
            foreach (Token token in tables.Tokens)
            {
                string value = tables.GetTokenValue(token);
                Console.WriteLine(string.Format("({0:D3}) Token: {3}, {1}, {2}", token.LineNumber, token.Type.ToString(), token.TableIndex, value));
            }

            Console.WriteLine();

            // Print errors...
            foreach (LexerError error in tables.Errors)
                Console.WriteLine(string.Format("({0:D3}) Error: {1}", error.LineNumber, error.Description));
        }
    }
}
